﻿@model RonYee.ViewModels.ShoppingCartViewModel

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">
    $(function () {
        //Document.ready -> link up remove event handler
        $(".RemoveLink").click(function () {
            //Get the id from the link
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                //Perform the ajax post
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                    function (data) {
                        //Successful requests get here
                        //Update the page elements
                        if (data.ItemCount == 0) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                        } else {
                            $('#row-count-' + data.DeleteId).text(data.ItemCount);
                        }
                        $('#cart-total').text(data.CartTotal);
                        $('#update-message').text(Date.Message);
                        $('#cart-status').text('Cart(' + data.CartCount + ')');

                    });
            }
        });
    });

</script>



<h3><em>Review</em> your cart</h3>

<div id="update-message"></div>
<table class="MyTable">
     <tr>
        <th>
           选项
        </th>
        <th>
           ISBN
        </th>
        <th>
           书 名
        </th>
        <th>
           价 格
        </th>
        <th>
           数 量
        </th>
         <th>
         
        </th>
     </tr>
     @foreach (var item in Model.CartItems) {
    <tr id="row-@item.RecordId">
        <td>
           <input type="checkbox" id="Check" />
        </td>
        <td>
           <a href="@Url.Action("Details", "Store", new { id = item.BookId })">@item.Book.ISBN</a>
         </td>
        <td>
            <a href="@Url.Action("Details", "Store", new { id = item.BookId })">@item.Book.BookName</a>
         </td>
         <td>
            @item.Book.CurrentPrice
         </td>
         <td id="item-count-@item.RecordId">
            @item.Count
          </td>
          <td>
             <a href="#" class="RemoveLink" data-id="@item.RecordId">移除该项</a>
            </td>
      </tr>
      }
      <tr>
        <td>
            Total
        </td>
        <td id="cart-total" colspan="5">
            @Model.CartTotal
        </td>
    </tr>
</table>
<p class="button">
  <a href="@Url.Action("CheckPhoneNumber", "Checkout")"><input type="button" value="结算并提交订单>>" class="red" /></a> 
  <a href="@Url.Action("Index", "Store")"><input type="button" value="继续购书" class="red" /></a>
</p>



